<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "bonus".
 *
 * @property integer $id
 * @property integer $user_id
 * @property integer $bonus_type_id
 * @property string $money
 * @property string $min_amount
 * @property integer $started_at
 * @property integer $ended_at
 * @property string $sn
 * @property integer $order_id
 * @property integer $used_at
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $created_by
 * @property integer $updated_by
 *
 * @property BonusType $bonusType
 */
class Bonus extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'bonus';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'bonus_type_id', 'money', 'started_at', 'ended_at', 'created_at', 'updated_at', 'created_by', 'updated_by'], 'required'],
            [['user_id', 'bonus_type_id', 'started_at', 'ended_at', 'order_id', 'used_at', 'created_at', 'updated_at', 'created_by', 'updated_by'], 'integer'],
            [['money', 'min_amount'], 'number'],
            [['sn'], 'string', 'max' => 255],
            [['bonus_type_id'], 'exist', 'skipOnError' => true, 'targetClass' => BonusType::className(), 'targetAttribute' => ['bonus_type_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'bonus_type_id' => 'Bonus Type ID',
            'money' => 'Money',
            'min_amount' => 'Min Amount',
            'started_at' => 'Started At',
            'ended_at' => 'Ended At',
            'sn' => 'Sn',
            'order_id' => 'Order ID',
            'used_at' => 'Used At',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
            'created_by' => 'Created By',
            'updated_by' => 'Updated By',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBonusType()
    {
        return $this->hasOne(BonusType::className(), ['id' => 'bonus_type_id']);
    }
}
